import 'package:flutter/material.dart';
import '../widgets/form/DDPasswordField.dart';
import '../widgets/form/DDReadField.dart';
import '../widgets/form/MyTextField.dart';

// Create a Form Widget
class TestEditForm extends StatefulWidget {
  @override
  _TestEditFormState createState() => _TestEditFormState();
}

// Create a corresponding State class. This class will hold the data related to
// the form.
class _TestEditFormState extends State<TestEditForm> {
  // Create a global key that will uniquely identify the Form widget and allow
  // us to validate the form
  //
  // Note: This is a GlobalKey<FormState>, not a GlobalKey<MyCustomFormState>!
  final _formKey = GlobalKey<FormState>();
  TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return _buildForm(context);
  }

  Widget _buildGrid(BuildContext context) {
    final title = 'Grid List';

    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: GridView.count(
        // Create a grid with 2 columns. If you change the scrollDirection to
        // horizontal, this would produce 2 rows.
        crossAxisCount: 2,
        // Generate 100 Widgets that display their index in the List
        children: List.generate(100, (index) {
          return Center(
            child: Text(
              'Item $index',
              style: Theme.of(context).textTheme.headline,
            ),
          );
        }),
      ),
    );
  }

  Widget _buildForm(BuildContext context) {
    // Build a Form widget using the _formKey we created above
    return Scaffold(
      appBar: AppBar(
        title: Text('自定义表单'),
      ),
      body: new Form(
        key: _formKey,
        child: ListView(
          children: <Widget>[
            TextFormField(
              initialValue: "",
              validator: (value) {
                if (value.isEmpty) {
                  return '请选择品牌';
                }
              },
            ),
            TextFormField(
              validator: (value) {
                if (value.isEmpty) {
                  return '请选择车系';
                }
              },
            ),
            TextFormField(
              validator: (value) {
                if (value.isEmpty) {
                  return '请选择车型';
                }
              },
            ),
            MyTextField(
              fieldKey: Key("MarketPrice"),
              labelText: "指导价格",
              hintText: "0.00",
              helperText: "请输入市场指导价格",
              validator: (value) {
                if (value.isEmpty) {
                  return '请选择车型';
                }
              },
            ),
            TextFormField(
              initialValue: "0.00",
              decoration: new InputDecoration(
                border: OutlineInputBorder(borderSide: BorderSide()),
                prefixIcon: Row(
                  children: [
                    Text("实际价格"),
                    Text("*", style: TextStyle(color: Colors.red)),
                  ],
                ),
                // prefixIcon: Text("实际价格"),
                prefixText: "￥",
                suffixText: "元",
              ),
              validator: (value) {
                if (value.isEmpty) {
                  return '请选择车型';
                }
              },
            ),
            TextField(
              controller: _controller,
              keyboardType: TextInputType.number,
              decoration: new InputDecoration(
                contentPadding: EdgeInsets.all(2.0),
                border: OutlineInputBorder(borderSide: BorderSide()),
                prefixIcon: SizedBox(
                  width: 90.0,
                  child: Row(
                    children: [
                      Text("指导价格1"),
                      Text(" *", style: TextStyle(color: Colors.red)),
                    ],
                  ),
                ),
                // prefixIcon: Text("指导价格"),
                prefixText: "￥",
                hintText: "请输入指导价格",
                suffixText: "元",
              ),
            ),
            TextField(
              controller: _controller,
              keyboardType: TextInputType.number,
              decoration: new InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                border: UnderlineInputBorder(borderSide: BorderSide()),
                prefixIcon: SizedBox(
                  width: 90.0,
                  child: Row(
                    children: [
                      Text("借款金额"),
                      Text(" *", style: TextStyle(color: Colors.red)),
                    ],
                  ),
                ),
                // prefixIcon: Text("借款金额"),
                prefixText: "￥",
                hintText: "请输入借款金额",
                suffixText: "元",
              ),
            ),
            new DDPasswordField(
              //fieldKey: _passwordFieldKey,
              helperText: 'No more than 8 characters.',
              labelText: 'Password *',
              onFieldSubmitted: (String value) {
                // setState(() {
                //   person.password = value;
                // });
              },
            ),
            new DDReadField(
              labelText: "姓名",
              valueText: "陈小生",
            ),
            new DDReadField(
              labelText: "性别",
              valueText: "男",
            ),
            new DDReadField(
              labelText: "出生日期",
              valueText: "1981-05-03",
            ),
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 16.0),
              child: RaisedButton(
                onPressed: () {
                  // Validate will return true if the form is valid, or false if
                  // the form is invalid.
                  if (_formKey.currentState.validate()) {
                    // If the form is valid, we want to show a Snackbar
                    Scaffold.of(context).showSnackBar(
                          SnackBar(
                            content: Text('Processing Data'),
                          ),
                        );
                  }
                },
                child: Text('Submit'),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildTab(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            tabs: [
              Tab(icon: Icon(Icons.directions_car)),
              Tab(icon: Icon(Icons.directions_transit)),
              Tab(icon: Icon(Icons.directions_bike)),
            ],
          ),
          title: Text('Tabs Demo'),
        ),
        body: TabBarView(
          children: [
            Icon(Icons.directions_car),
            Icon(Icons.directions_transit),
            Icon(Icons.directions_bike),
          ],
        ),
      ),
    );
  }
}
